package LeetCode;
import java.util.*;
public class LeetCodeMain10 {
    List<List<Integer>> list=new ArrayList<>();
    List<Integer> list1=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        boolean[]  booleans=new boolean[nums.length];
        back(nums,booleans);
        return list;
    }
    public void back(int[] nums,boolean[] booleans){
        if (list1.size()==nums.length){
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (booleans[i]==true){
                continue;
            }
            booleans[i]=true;
            list1.add(nums[i]);
            back(nums,booleans);
            list1.remove(list1.size()-1);
            booleans[i]=false;
        }
    }
}
